import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    todos: new Array(5).fill(null).map((u,i) => ({
      id: Math.random(),
      title: '陈症结'+ i,
      isok: false
    }))
  },
  mutations: {
    VuexAddtoList(state,title) {
      state.todos.unshift({
        id:Math.random(),
        title,
        isok: false
      })
    },
    VuexChangeList(state,id) {
      state.todos = state.todos.map(todo => {
        if(todo.id === id) {
          todo.isok = !todo.isok
        }
        return todo
      })
    },
    VuexremoveItem(state,id) {
      state.todos = state.todos.filter(todo => todo.id != id)
    }
  }
})

export default store